using GlobalEnums;
using HelloMods.Healths;
using Modding;
using System.Linq;
using System.Reflection;
using UnityEngine;

namespace HelloMods
{
    // Define a new mod named `SimpleHooks` that implements `ITogglableMod`
    // to signify that it can be toggled on or off.
    public class HelloMod : Mod, ITogglableMod
    {
        public HelloMod() : base("Hello-Mod")
        {

        }

        private PlayerScript script;

        // Store the currently loaded instance of the mod.
        public static HelloMod LoadedInstance { get; set; }


        // Override the `GetVersion` method to get the assembly version.
        public override string GetVersion() => Assembly.GetExecutingAssembly().GetName().Version.ToString();

        // Code that should run on mod initialization.
        //
        // If your mod implements `ITogglableMod`, this method will be run on loaded the mod up again
        // so make sure to write it in a way that it will not fail if ran multiple times.
        public override void Initialize()
        {
            this.LogWarn("HelloMod Initialize!");
            // Check if there is already a loaded mod instance.
            if (HelloMod.LoadedInstance != null) return;

            //    ModHooks.GetPlayerBoolHook += ModHooks_GetPlayerBoolHook;

            GameObject go = new GameObject();
            Object.DontDestroyOnLoad(go); 

            var script = go.AddComponent<PlayerScript>();
            PlayerScript.instance = script;
            script.enabled = true;

            // Set the mod instance
            HelloMod.LoadedInstance = this;
            // Log some message to `ModLog.txt` with info level logging.
            this.LogWarn("Press F10 To Hidden Console!");
        }
 
        private bool ModHooks_GetPlayerBoolHook(string name, bool orig)
        {
            var player = GameObject.FindGameObjectWithTag("Player");
            if (player && player.GetComponent<PlayerScript>() == null)
            {
                var script = player.AddComponent<PlayerScript>();
                PlayerScript.instance = script;
                script.enabled = true;
            }
            return orig;
        }




        // Code that should be run when the mod is disabled.
        public void Unload()
        {
            this.Log($"Unload  HelloMod");
 
            HelloMod.LoadedInstance = null;
        }

    }


}
